﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Reflection;

namespace Charisma.Tests
{
    public static class ConfigurationRegistryExtensions
    {
        private static FieldInfo repositories;
        private static FieldInfo entities;

        public static IndexedSet<string, RepositoryConfigurator> GetRepositories(this ConfigurationRegistry registry)
        {
            return (IndexedSet<string, RepositoryConfigurator>)repositories.GetValue(registry);
        }

        public static IndexedSet<Type, EntityConfigurator> GetEntities(this ConfigurationRegistry registry)
        {
            return (IndexedSet<Type, EntityConfigurator>)entities.GetValue(registry);
        }

        static ConfigurationRegistryExtensions()
        {
            var c = typeof(ConfigurationRegistry);
            repositories = c.GetField("Repositories", BindingFlags.Instance | BindingFlags.NonPublic);
            entities = c.GetField("Entities", BindingFlags.Instance | BindingFlags.NonPublic);
        }
    }
}
